// stores/cartStore.js
import { makeAutoObservable } from 'mobx'

class MenuStore {
  // 状态：购物车商品列表
  items = []

  constructor() {
    makeAutoObservable(this)
  }

  addItem = (product) => {
    this.items.push(product)
  }

  removeItem = (productId) => {
    this.items = this.items.filter((item) => item.id !== productId)
  }

  get totalCount() {
    return this.items.length
  }

  get totalPrice() {
    return this.items.reduce((sum, item) => sum + item.price, 0)
  }
}

export const menuStore = new MenuStore()
